package com.xinke.juc.case04;

import com.xinke.juc.util.Sleeper;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author：xinke
 * @Date：2025/10/3
 * @Desc:
 */
@Slf4j
public class WaitNotify02 {
    static final Object room = new Object();
    static boolean hasCigarette = false;
    static boolean hasTakeout = false;

    public static void main(String[] args) {
        new Thread(() -> {
            synchronized (room) {
                log.info("有烟没？【{}】", hasCigarette);
                if (!hasCigarette) {
                    log.info("没烟，先歇会！");
                    Sleeper.sleep(2);
                }
                log.info("有烟没？【{}】", hasCigarette);
                if (hasCigarette) {
                    log.info("可以开始干活了");

                }
            }
        }, "小南").start();

        for (int i = 0; i < 5; i++) {
            new Thread(() -> {
                synchronized (room) {
                    log.info("可以开始干活了");
                }
            }, "其他人").start();
        }

        Sleeper.sleep(1);
        new Thread(() -> {
            // 这里能不能加 synchronized (room)？
            hasCigarette = true;
            log.info("烟到了噢。。。");
        }, "送烟的").start();
    }
}
